package org.gd.spring.hibernate;

import org.gd.spring.hibernate.entity.P48CallableEntry;
import org.hibernate.Session;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

/**
 * @author Gorhover
 * @version 1.0-SNAPSHOT
 * @since 2013-10-03 09:38
 */
public class App2 {

    public static void main(String[] args) {
        Session session = null;
        try {
            ApplicationContext ac = new ClassPathXmlApplicationContext("hibernate/hibernate.context.xml");
            HibernateUtil hibernateUtil = ac.getBean("hibernateUtil", HibernateUtil.class);
            session = hibernateUtil.openSession();

            session.beginTransaction();

            P48CallableEntry entry = new P48CallableEntry();
            entry.setReference("ref1");
            entry.setBlob("Hello World!".getBytes());
            session.save(entry);

            session.getTransaction().commit();



        } catch (Throwable e) {
            e.printStackTrace(System.err);
        } finally {
            if(session != null) {
                session.close();
            }

        }
    }
}
